/*
 * HttpClient.h
 *
 *  Created on: 2017年3月31日
 *      Author: chuanjiang.zh
 */

#ifndef HTTPCLIENT_H_
#define HTTPCLIENT_H_

#include <iostream>
#include <time.h>
#include <functional>
#include <map>

struct http_message;

typedef std::function< void(int code, const char* body, size_t size, const http_message* msg) >    HttpClientCallback;


class HttpClient
{
public:
    typedef std::map< std::string, std::string >    StringMap;

public:
	virtual ~HttpClient() {}

    virtual bool get(const std::string& url, HttpClientCallback cb)
    {
        return request(url, "GET", StringMap(), std::string(), cb);
    }

    virtual bool get(const std::string& url, const StringMap& headers, HttpClientCallback cb)
    {
        return request(url, "GET", headers, std::string(), cb);
    }

	virtual bool post(const std::string& url, const std::string& body, HttpClientCallback cb)
    {
        return request(url, "POST", StringMap(), body, cb);
    }

    virtual bool post(const std::string& url, const StringMap& headers, const std::string& body, HttpClientCallback cb)
    {
        return request(url, "POST", headers, body, cb);
    }

    virtual bool put(const std::string& url, const std::string& body, HttpClientCallback cb)
    {
        return request(url, "PUT", StringMap(), body, cb);
    }

    virtual bool put(const std::string& url, const StringMap& headers, const std::string& body, HttpClientCallback cb)
    {
        return request(url, "PUT", headers, body, cb);
    }

    virtual bool del(const std::string& url, const std::string& body, HttpClientCallback cb)
    {
        return request(url, "DELETE", StringMap(), body, cb);
    }

    virtual bool del(const std::string& url, const StringMap& headers, HttpClientCallback cb)
    {
        return request(url, "DELETE", headers, std::string(), cb);
    }

	virtual bool request(const std::string& url, const std::string& httpMethod, const StringMap& headers, const std::string& body,
		HttpClientCallback cb) =0;


	virtual void close() =0;

	virtual bool isOpen() =0;

	virtual void setTimeout(int seconds) = 0;

};

#endif /* HTTPCLIENT_H_ */
